<?php
session_cache_expire(999999999);
if(!isset($_SESSION)) 
	{ 
		session_start(); 
	}
if(!isset($_SESSION['db'])){
	$addressbrowser = $_SERVER['SERVER_NAME'];
	$temp = explode(".", $addressbrowser);
	$connection = mysql_connect("1.234.53.52", "cam", "5678" ) ;
	//$connection = mysql_connect("localhost", "root", "root" ) ;
	mysql_select_db("elihan", $connection);
	mysql_query("set names 'utf8'");
	$selectdatabase = mysql_query("SELECT am.DatabaseName,am.Logo from ac_eli_manager am where am.KeyName='$temp[0]' and am.`Status` = 2");
	$result = mysql_fetch_assoc($selectdatabase);

	$_SESSION['Logo']=$result[Logo];
	$_SESSION['db']= $result[DatabaseName];
	mysql_close($connection);
}
$database = $_SESSION['db'];


$sql="SELECT count(IDTypeDoc) as RePendingDoc   FROM approvedoc a , listapprove b
		WHERE b.IDEmployee = $id_employee
		AND a.IDGroupApprove = b.IDGroupApprove
		AND a.IDTypeDoc  != 11
		AND a.IDStatus  = 2
		AND b.IDStatus  = 1";
$mysql=mysql_query($sql);
$r=mysql_fetch_array($mysql);
$num_re_pending = $r['RePendingDoc'];

//ReNotApprovedDoc
$sql="SELECT count(IDTypeDoc) as ReNotApprovedDoc FROM approvedoc a , listapprove b 
		WHERE b.IDEmployee = $id_employee 
		AND a.IDGroupApprove = b.IDGroupApprove
		AND a.IDTypeDoc != 11
		AND a.IDStatus = 2
		AND b.IDStatus = 2";
$mysql=mysql_query($sql);
$r=mysql_fetch_array($mysql);
$num_re_not_approve = $r['ReNotApprovedDoc'];

//ReApprovedDoc
$sql="SELECT count(IDTypeDoc) as ReApprovedDoc  FROM approvedoc a ,listapprove b 
		WHERE b.IDEmployee = $id_employee
		AND a.IDGroupApprove = b.IDGroupApprove
		AND a.IDTypeDoc != 11
		AND a.IDStatus = 1 
		AND b.IDLabel < 1
		AND b.IDStatus = 1";
$mysql=mysql_query($sql);
$r=mysql_fetch_array($mysql);
$num_re_approved= $r['ReApprovedDoc'];

//ReDeclinedDoc
$sql="SELECT count(IDTypeDoc) as ReDeclinedDoc  FROM approvedoc a , listapprove b 
		WHERE b.IDEmployee = $id_employee
		AND a.IDGroupApprove = b.IDGroupApprove
		AND a.IDTypeDoc != 11
		AND a.IDStatus = 3 
		AND b.IDLabel < 1
		AND b.IDStatus = 3";
$mysql=mysql_query($sql);
$r=mysql_fetch_array($mysql);
$num_re_declined = $r['ReDeclinedDoc'];

//ReRefApprovedDoc
$sql="SELECT count(IDTypeDoc) as ReRefApprovedDoc  FROM approvedoc p ,list_reference l 
		WHERE l.id_employee = $id_employee
		AND p.IDGroupApprove = l.id_group 
		AND p.IDTypeDoc != 11 
		AND l.IDLabel < 1
		AND l.id_status = 1";
$mysql=mysql_query($sql);
$r=mysql_fetch_array($mysql);
$num_re_reference_approved = $r['ReRefApprovedDoc'];

//ReRefWaitingDoc
$sql="SELECT count(IDTypeDoc) as ReRefWaitingDoc FROM approvedoc p, list_reference l  
		WHERE l.id_employee = $id_employee
		AND p.IDGroupApprove = l.id_group 
		AND p.IDTypeDoc != 11
		AND l.id_status = 2";
$mysql=mysql_query($sql);
$r=mysql_fetch_array($mysql);
$num_re_reference_waiting = $r['ReRefWaitingDoc'];

//ReMeetingDoc
$sql="SELECT count(IDTypeDoc) as ReMeetingDoc  FROM approvedoc a ,listapprove b 
		WHERE b.IDEmployee  = $id_employee
		AND a.IDGroupApprove = b.IDGroupApprove
		AND a.IDTypeDoc = 11
		AND a.IDStatus = 2
		AND b.IDStatus = 2";
$mysql=mysql_query($sql);
$r=mysql_fetch_array($mysql);
$num_re_received_metting = $r['ReMeetingDoc'];

//MySendingDoc
$sql="SELECT count(IDTypeDoc) as MySendingDoc from approvedoc a
		WHERE a.IDStatus = 2
		AND a.IDEmployee = $id_employee
		AND a.IDTypeDoc != 11";
$mysql=mysql_query($sql);
$r=mysql_fetch_array($mysql);
$num_my_sendingDoc=$r['MySendingDoc'];

//MySavedDoc
$sql="SELECT count(IDTypeDoc) as MySavedDoc from approvedoc a
		WHERE a.IDStatus = 4
		AND a.IDEmployee = $id_employee";
$mysql=mysql_query($sql);
$r=mysql_fetch_array($mysql);
$num_my_savedDoc=$r['MySavedDoc'];

//MyApproveDoc
$sql="SELECT count(IDTypeDoc) as MyApproveDoc from approvedoc a
		WHERE a.IDStatus = 1 
		AND a.IDLabel < 1
		AND a.IDEmployee = $id_employee";
$mysql=mysql_query($sql);
$r=mysql_fetch_array($mysql);
$num_my_approveDoc=$r['MyApproveDoc'];

//MyDeclinedDoc
$sql="SELECT count(IDTypeDoc) as MyDeclinedDoc from approvedoc a
		WHERE a.IDStatus = 3 
		AND a.IDLabel < 1
		AND a.IDEmployee = $id_employee";
$mysql=mysql_query($sql);
$r=mysql_fetch_array($mysql);
$num_my_declinedDoc=$r['MyDeclinedDoc'];

//MyMeetingDoc
$sql="SELECT count(IDTypeDoc) as MyMeetingDoc from approvedoc a
		WHERE a.IDStatus = 2
		AND a.IDTypeDoc = 11
		AND a.IDEmployee = $id_employee";
$mysql=mysql_query($sql);
$r=mysql_fetch_array($mysql);
$num_my_meetingDoc=$r['MyMeetingDoc'];

//BinReceiverDoc
$sql="SELECT count(IDTypeDoc) as BinReceiverDoc  FROM approvedoc a ,listapprove b  
		WHERE b.IDEmployee = $id_employee
		AND a.IDGroupApprove = b.IDGroupApprove
		AND a.IDTypeDoc != 11
		AND a.IDStatus = 6
		AND b.IDStatus = 1";
$mysql=mysql_query($sql);
$r=mysql_fetch_array($mysql);
$num_bin_re_doc = $r['BinReceiverDoc'];

//BinSendingDoc
$sql="SELECT count(IDTypeDoc) as BinSendingDoc from approvedoc a
		WHERE a.IDStatus = 6
		AND a.IDEmployee = $id_employee";
$mysql=mysql_query($sql);
$r=mysql_fetch_array($mysql);
$num_bin_se_doc = $r['BinSendingDoc'];

?>